package org.answer.controller;

/*
    预约列表
 */

import org.answer.constant.MessageConstant;
import org.answer.entity.PageResult;
import org.answer.entity.QueryPageBean;
import org.answer.entity.Result;
import org.answer.pojo.*;
import org.answer.service.OrderSettingListService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/orderSettingList")
public class OrderSettingListController {

    //dubbo远程调用service
    @Reference
    private OrderSettingListService orderSettingListService;


    //添加套餐表数据回显
    @RequestMapping("/create")
    public Result Create() {

        try {
            List<Setmeal> list = orderSettingListService.create();
            return new Result(true, "套餐数据会显失败", list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "套餐数据会显失败");
        }
    }

    //分页查询，条件查询
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {

        try {
            PageResult page = orderSettingListService.findPage(queryPageBean);
            return page;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    //添加
    @RequestMapping("/add")
    public Result add(@RequestBody Member member, Integer[] setmealIds) {
        if (setmealIds.length == 0) {
            return new Result(false, "预约项目不能为空，请重新预约操作");
        }
        try {
            orderSettingListService.add(member, setmealIds);
            return new Result(true, MessageConstant.ORDER_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDERSETTING_FAIL);
        }
    }

    //确认预约
    @RequestMapping("/update")
    public Result update(@RequestBody OrderSettingList orderSettingList){
        try {
            orderSettingListService.update(orderSettingList);
            return new Result(true,MessageConstant.ORDER_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.ORDER_FULL);
        }
    }

    //删除预约
    @RequestMapping("/delete")
    public Result delete(@RequestBody OrderSettingList orderSettingList){

        try {
            orderSettingListService.delete(orderSettingList);
            return new Result(true,"取消预约成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"取消预约失败");
        }

    }


}


